package com.ruoyi.web.controller.linkage.linkageStrategy;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.linkage.domain.LinkageAction;
import com.ruoyi.linkage.service.ILinkageActionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 联动策略-动作Controller
 *
 * @author pengjie
 * @date 2023-12-20
 */
@RestController
@RequestMapping("/linkage/action")
public class LinkageActionController extends BaseController
{
    @Autowired
    private ILinkageActionService linkageActionService;

    /**
     * 查询联动策略-动作列表
     */
    @PreAuthorize("@ss.hasPermi('linkage:action:list')")
    @GetMapping("/list")
    public TableDataInfo list(LinkageAction linkageAction)
    {
        startPage();
        List<LinkageAction> list = linkageActionService.selectLinkageActionList(linkageAction);
        return getDataTable(list);
    }

    /**
     * 导出联动策略-动作列表
     */
    @PreAuthorize("@ss.hasPermi('linkage:action:export')")
    @Log(title = "联动策略-动作", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, LinkageAction linkageAction)
    {
        List<LinkageAction> list = linkageActionService.selectLinkageActionList(linkageAction);
        ExcelUtil<LinkageAction> util = new ExcelUtil<LinkageAction>(LinkageAction.class);
        util.exportExcel(response, list, "联动策略-动作数据");
    }

    /**
     * 获取联动策略-动作详细信息
     */
    @PreAuthorize("@ss.hasPermi('linkage:action:query')")
    @GetMapping(value = "/{linkageActionId}")
    public AjaxResult getInfo(@PathVariable("linkageActionId") String linkageActionId)
    {
        return success(linkageActionService.selectLinkageActionByLinkageActionId(linkageActionId));
    }

    /**
     * 新增联动策略-动作
     */
    @PreAuthorize("@ss.hasPermi('linkage:action:add')")
    @Log(title = "联动策略-动作", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody LinkageAction linkageAction)
    {
        return toAjax(linkageActionService.insertLinkageAction(linkageAction));
    }

    /**
     * 修改联动策略-动作
     */
    @PreAuthorize("@ss.hasPermi('linkage:action:edit')")
    @Log(title = "联动策略-动作", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody LinkageAction linkageAction)
    {
        return toAjax(linkageActionService.updateLinkageAction(linkageAction));
    }

    /**
     * 删除联动策略-动作
     */
    @PreAuthorize("@ss.hasPermi('linkage:action:remove')")
    @Log(title = "联动策略-动作", businessType = BusinessType.DELETE)
	@DeleteMapping("/{linkageActionIds}")
    public AjaxResult remove(@PathVariable String[] linkageActionIds)
    {
        return toAjax(linkageActionService.deleteLinkageActionByLinkageActionIds(linkageActionIds));
    }
}
